package com.atguigu.redisconfig;

import com.atguigu.constant.RedisConst;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class ShopMessageListener {
    @Autowired
    private RedisTemplate redisTemplate;

    //具体处理消息的方法
    public void receiveChannelMessage(String message){
        //""24:1""
        if(!StringUtils.isEmpty(message)){
            message= message.replaceAll("\"","");
            String[] splitMessage = message.split(":");
            if(splitMessage.length==2){
                //splitMessage[0]是商品的skuId,splitMessage[1]秒杀状态位
                redisTemplate.opsForValue().set(RedisConst.SECKILL_STATE_PREFIX+splitMessage[0],splitMessage[1]);
            }
        }

    }
}
